/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package webservice;

import entity.Regalo;
import entity.Utente;
import facade.UtenteFacadeLocal;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
 *
 * @author erola
 */
@WebService(wsdlLocation = "WEB-INF/wsdl/WLWebServiceService.wsdl")
public class WLWebService {

    @EJB
    private UtenteFacadeLocal utenteFacade;

    /**
     * Web service operation
     */
    @WebMethod(operationName = "listaUtenti")
    public String listaUtenti() {
        List<Utente> lista = utenteFacade.findAll();
        String result = "<utenti>";
        for (Utente u : lista) {
            result += "<utente>";
            result += "<id>" + u.getId() + "</id>";
            result += "<login>" + u.getLogin() + "</login>";
            result += "<nome>" + u.getNome() + "</nome>";
            result += "<cognome>" + u.getCognome() + "</cognome>";
            result += "</utente>";
        }
        result += "</utenti>";
        return result;
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "listaRegali")
    public String listaRegali(@WebParam(name = "uid") Long uid) {
        Utente u = utenteFacade.find(uid);
        ArrayList<Regalo> lista = u.getLista();
        String result = "<regali>";
        for (Regalo r : lista) {
            result += "<regalo>";
            result += "<id>" + r.getId() + "</id>";
            result += "<nome>" + r.getNome() + "</nome>";
            result += "<tipo>" + r.getTipo() + "</tipo>";
            result += "<descrizione>" + r.getDescrizione() + "</descrizione>";
            result += "</regalo>";
        }
        result += "</regali>";
        return result;
    }
}
